<?php
/**
 * 监听进程启动事件
*/

namespace event\rpc;

class onWorkerStart
{
    /**
	 * 启动实例
	*/
    public $server;
    
    /**
     * 统一回调入口
    */
    public function run(\Workerman\Worker $server) {
        $this->server = $server;
        $this->mount($server->id);
        
        // 调用二次转发，不做重载
        $on = new \event\server\onWorkerStart;
        $on->run($server);
        
        // 生命周期转发
        \houze\Lifecycle::worker_start($server->id);
    }
    
    /**
     * 任务挂载
    */
    private function mount($workerId) {
        // 启动异步进程服务
        \houze\MountEvent::WorkerStart_Task();
        // 初始化RPC路由
        \houze\MountEvent::WorkerStart_RouteStart_Rpc();
        // 挂载Rpc服务中心监测器
        \houze\MountEvent::WorkerStart_RpcClient($workerId);
        // 载入路由限流器重置定时任务
        \houze\MountEvent::WorkerStart_LimitRouteReset($this->server, $workerId, 'http');
        // 载入IP限流器重置定时任务
        \houze\MountEvent::WorkerStart_LimitIpReset($this->server, $workerId);
        // 载入定时任务
        \houze\MountEvent::WorkerStart_Crontab($this->server, $workerId);
    }

}

